<?php

require_once '../lib/Store.php';

$scriptName = $_SERVER['SCRIPT_NAME'];
$contextUrl = cropToLastFinding($scriptName, '/');
$baseUrl = 'http://' . $_SERVER['HTTP_HOST'] . $contextUrl;

function cropToLastFinding($str, $toFind) {
	return substr($str, 0, strrpos($str, $toFind));
}

function hasAccessToken() {
	$store = GG_API_Store::getDefault();
	$token = $store->getOauthToken();
	$tokenSecret = $store->getOauthTokenSecret();
	return !empty($token) && !empty($tokenSecret);
}

?>
<table border="0" cellpadding="0" cellspacing="5">
	<tr>
		<td><a href="<?= $baseUrl ?>/index.php">Index</a></td>
		<td>
<form action="<?= $baseUrl ?>/authorize.php" style="margin-bottom: 0;">
<?php if (hasAccessToken()) { ?>
	<input type="hidden" name="action" value="logout"/>
	<input type="submit" value="Logout"/>
<?php } else { ?>
	<input type="hidden" name="action" value="requestToken"/>
	<input type="submit" value="Login with Annonsera.se"/>
<?php } ?>
</form>
		</td>
	</tr>
</table>

